<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width" />
    <title>test</title>
    <script src="./jquery-3.3.1.min.js"></script>
    <script src="./jsencrypt.min.js"></script>
    
</head>
<body>
    <div>
        <input type="button" id="btn" value="点我" />
		<textarea id="data" rows="15" cols="65">test</textarea>
		<textarea id="PublicKey" rows="15" cols="65">-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC6LKFg1wEBn2PWKShPOL2JbcQN
WOp9zYq1Pumq/Y0moRWSmJNlZKS86KUYIwtyHlDC6Cqd3D6TfmqWm/S3sKkARvoh
f1+/jloznu31cKueAdrct14K/TDqdSLbmzNe/xeTptkyQePSgnbZi1hIIusxvMum
htumvqEb0oF7iLbOjwIDAQAB
-----END PUBLIC KEY-----</textarea>
		<textarea id="PrivateKey" rows="15" cols="65">-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQC6LKFg1wEBn2PWKShPOL2JbcQNWOp9zYq1Pumq/Y0moRWSmJNl
ZKS86KUYIwtyHlDC6Cqd3D6TfmqWm/S3sKkARvohf1+/jloznu31cKueAdrct14K
/TDqdSLbmzNe/xeTptkyQePSgnbZi1hIIusxvMumhtumvqEb0oF7iLbOjwIDAQAB
AoGAcLIJcexUIJ5SOdYqH2JyYRk/vvCe6U4dc79EhQv8gHCr9VREjPDSQ8P0A9ta
11aAfqs4+NvUSUYR0V9QUE0wzwB03KbreDBUWL0lZ69QPP6pCL7u92DGOE2Ht8+n
mzkgRc/1CqzG5d5qRcn9PQUBCUVvpbVY1t6trsFDATCffWECQQDmmC8RS+gm1yIP
O1V6kCaeV6A5M0U4f8i2UKQhCHXM6m/SAyVjwjWc+Ov7EQzrNoa9L5sqFJgrj7Fz
gOyBhum/AkEAzq+YnhMf2rV3eLlPsyaR80LdPuI0pzkrKyLLSFPrx2nWh0wCKCGp
C6raXS6/j+s/DghfChww43uSgM4RIYYvMQJAR/GNJclX+d4/Cx+I8L9OvTI7k/0S
CKmdlnwcaQ35quAt2QkQPkqWbY4gGenc7PnLGfVjZMKeI2EmjRHZOCQ+gwJAVyDI
2mI/fGghHAAqa+AniH+4Wqjq/09nNkDtpujRrPed2t0cz6QY6fU1JjDtyhKmOxkm
T1HA/jR6dtfnetVhEQJBAN3ZA3pHM/yJOOBiBSwl8HFjbUJMLvnhMf2TwG4Vc96n
mtTEgh/5Kdg/WQVP5FPuOwHgBhAMezkNrwHRUnzUjSw=
-----END RSA PRIVATE KEY-----</textarea>
        <hr/>
        注意+好的处理
    </div>
	<script type="text/javascript">
        $(function () {
            var encrypt = new JSEncrypt();
			//crypt.setKey(__YOUR_OPENSSL_PRIVATE_OR_PUBLIC_KEY__); //You can use also setPrivateKey and setPublicKey, they are both alias to setKey
            encrypt.setPublicKey($("#PublicKey").val());
            var encryptData = encrypt.encrypt("test");
            //alert(encryptData);
			encrypt.setPrivateKey($("#PrivateKey").val());
			var decryptData = encrypt.decrypt(encryptData);
			//alert(decryptData);
			$("#data").val(encryptData);
			//alert(encodeURI(encryptData).replace("/\+/g", '%2B'));
            $("#btn").click(function () {
                $.ajax({
                    url: 'http://cnxel.cn:8686/PC_APP_API/Login_Administrator',
                    data: {data:""+encodeURI(encryptData).replace("/\+/g", '%2B')},  //+号的处理：因为数据在网络上传输时，非字母数字字符都将被替换成百分号（%）后跟两位十六进制数，而base64编码在传输到后端的时候，+会变成空格，因此先替换掉。后端再替换回来
                    type: 'post',
                    success: function (msg) {
                        alert(msg);
                    }
                });
            });

        });


    </script>
</body>
</html>